#define _CRT_SECURE_NO_WARNINGS 1

class Solution {
public:
    int lengthOfLongestSubstring(string s) {
        int len = 0;
        vector<int> v;
        v.resize(128, -1);
        int left, right;
        for (left = -1, right = 0; right < s.size(); right++)
        {
            if (v[s[right]] != -1)
            {
                if (len < right - left - 1)
                    len = right - left - 1;
                while (left < v[s[right]])
                    v[s[++left]] = -1;
            }
            v[s[right]] = right;
        }
        if (len < right - left - 1)
            len = right - left - 1;
        return len;
    }
};